# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=typo3scan
_pkgname=Typo3Scan
pkgver=v1.2.final.r0.g0c4ec73
pkgrel=5
pkgdesc='Enumerate Typo3 version and extensions.'
arch=('any')
groups=('blackarch' 'blackarch-webapp' 'blackarch-scanner')
url='https://github.com/whoot/Typo3Scan'
license=('GPL-2.0-or-later')
depends=('python' 'python-requests' 'python-colorama' 'python-progressbar'
         'python-setuptools' 'python-beautifulsoup4' 'python-fake-useragent')
makedepends=('git')
replaces=('typo-enumerator')
source=("git+https://github.com/whoot/$_pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $_pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" doc/* *.md

  cp -a $pkgname.py lib "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python $pkgname.py "\$@"
EOF

  chmod a+x "$pkgdir/usr/bin/$pkgname"
}

